package com.cnplan.controller;

import com.cnplan.core.KUtil;
import com.cnplan.entity.ArcMain;
import com.cnplan.service.ArcMainService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/arc_main")
public class ArcMainController {

    @Autowired
    private ArcMainService arcMainService;

    @GetMapping("/findpage")
    public Object findPage(@RequestParam Map map){
        return arcMainService.findByArcMain(map);
    }

    @GetMapping("/list")
    public String archivesList(@RequestParam Map map, Model model){
        PageInfo pageInfo=arcMainService.findByArcMain(map);
        String featureType=map.get("featureType").toString();
        model.addAttribute("mapData",map);
        if("zh".equals(featureType)){
            List<ArcMain> arcMainList=pageInfo.getList();
            for (ArcMain arcMain:arcMainList) {
                arcMain.setFeatureName(KUtil.daoHangT1(arcMain.getFeatureType()));
            }
            model.addAttribute("pageInfo",pageInfo);
            return "archives/arcfmainzh";
        }else if("fin".equals(featureType)){
            model.addAttribute("pageInfo",pageInfo);
            //执照
            return "archives/arcfmainfin";
        }else if("lic".equals(featureType)){
            model.addAttribute("pageInfo",pageInfo);
            //竣工
            return "archives/arcfmainfin";
        }else if("earth".equals(featureType)){
            //建设用地
            model.addAttribute("pageInfo",pageInfo);
            return "archives/arcfmainearth";
        }else if("check".equals(featureType)){
            model.addAttribute("pageInfo",pageInfo);
            //规划验收
            return "archives/arcfmaincheck";
        }else if("punish".equals(featureType)){
            model.addAttribute("pageInfo",pageInfo);
            //规划处罚
            return "archives/arcfmainpunish";
        }else if("plan".equals(featureType)){
            model.addAttribute("pageInfo",pageInfo);
            //规划档案
            return "archives/arcfmainplan";
        }else if("land".equals(featureType)){
            model.addAttribute("pageInfo",pageInfo);
            //土地管理档案
            return "archives/arcfmainplan";
        }else{
            model.addAttribute("pageInfo",pageInfo);
            return "archives/arcfmain";
        }

    }

    @GetMapping("/listTest")
    public String archivesListtest(){
        return "archives/imageTest";
    }
}
